package com.datastructure.test.sumofleftleaves;

public class SumOfLeftLeaves {

    public int result;
    public static void main(String[] args) {

    }

    public int sumOfLeftLeaves (TreeNode root) {
        // write code here
        if(root==null){
            return 0;
        }
        computeTreeNode(root);
        return result;
    }

    private void computeTreeNode(TreeNode root) {
        if(root==null){
            return;
        }
        if(root.left!=null&&root.left.left==null&&root.left.right==null){
            result+=root.left.val;
        }
        computeTreeNode(root.left);
        computeTreeNode(root.right);
    }
}

class TreeNode {
   int val = 0;
   TreeNode left = null;
   TreeNode right = null;
   public TreeNode(int val) {
     this.val = val;
   }
 }
